//
//  myView.m
//  LiWuShuo
//
//  Created by 苗钧豪 on 16/8/2.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "myView.h"
#import "CollectionViewCell.h"
@implementation myView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _field = [[UITextField alloc]initWithFrame:CGRectMake(20, 10, self.bounds.size.width - 40, 30)];
        _field.placeholder = @"快选一份七夕礼物，送给心爱的Ta吧";
        [self addSubview:_field];
        _label = [[UILabel alloc]initWithFrame:CGRectMake(0, 45, 100, 30)];
        _label.text = @"栏目";
        [self addSubview:_label];
        _btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_btn setTitle:@"查看更多＞" forState:(UIControlStateNormal)];
        [_btn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        _btn.frame = CGRectMake(self.bounds.size.width - 140, 45, 100, 30);
        [self addSubview:_btn];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        _collectionview.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.itemSize = CGSizeMake(self.bounds.size.width - 100, 120);
        layout.minimumInteritemSpacing = 5;
        layout.minimumLineSpacing = 20;
        _collectionview = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 80, self.bounds.size.width, self.bounds.size.height) collectionViewLayout:layout];
        _collectionview.delegate = self;
        _collectionview.dataSource = self;
        [_collectionview registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"2"];
        _collectionview.backgroundColor = [UIColor whiteColor];
        [self addSubview:_collectionview];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 9;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"2" forIndexPath:indexPath];
    cell.imgview.image = [UIImage imageNamed:[NSString stringWithFormat:@"m%ld",indexPath.row + 12]];
//    cell.contentView.backgroundColor = [UIColor cyanColor];
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
